// functionPage/pages/minePage/mySubmitInfo/mySubmitInfo.js
import Http from '../../../../utils/http.js';
import { scrollToLeftEnd } from '../../../../utils/behavior';
const http = new Http();
const app = getApp();

Page({
    behaviors: [scrollToLeftEnd],
    /**
     * 页面的初始数据
     */
    data: {
        authId: '',
        uid: '',
        otherPage: '',
        tabsArr: ['FT测试', 'NFC测试', '运营商', '车食住行'],
        currentTabIndex: 0,
        index: Number,
        //ft测试
        ftContentArr: [],
        ftPageNo: 0,
        ftContentLength: 0,
        ftLoading: false,
        //nfc测试
        nfcContentArr: [],
        nfcPageNo: 0,
        nfcContentLength: 0,
        nfcLoading: false,
        //运营商
        yysContentArr: [],
        yysPageNo: 0,
        yysContentLength: 0,
        yysLoading: false,
        //车食住行
        cszxContentArr: [],
        cszxPageNo: 0,
        cszxContentLength: 0,
        cszxLoading: false,
        lastest: {
            review_title: '暂无消息',
        }, // 最近第一条审核消息
        unreadCount: 0, // 未读消息数
        showNewBox: true, //产看他人主页隐藏消息提示
    },
    pageTap(e) {
        if (e.currentTarget.dataset.delflg == '01') {
            wx.showToast({
                title: '当前数据已被删除',
                icon: 'none', //如果要纯文本，不要icon，将值设为'none'
                duration: 2000,
            });
            return;
        }
        wx.navigateTo({
            url: e.currentTarget.dataset.url,
        });
        this.setData({
            index: e.currentTarget.dataset.index,
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let title = '我的录入·';
        if (options.uid) {
            this.setData({
                uid: options.uid,
                otherPage: '02', //查看他人主页权限
                showNewBox: !options.uid,
            });
            title = '录入·';
        } else {
            this.setData({
                uid: app.globalData.uid,
                showNewBox: !options.uid,
            });
        }
        wx.setNavigationBarTitle({
            title: title + options.enterNum,
            success: (result) => {},
            fail: () => {},
            complete: () => {},
        });
        this.getftList();
        this.getnfcList();
        this.getyysList();
        this.getcszxList();
    },
    refresh() {
        let _that = this;
        let index = _that.data.index;
        let data = {
            authId: app.globalData.authId,
            pageNo: 1,
            pageSize: index + 1,
            createuid: _that.data.uid,
            delflg: 'mine',
        };
        if (_that.data.currentTabIndex == 0) {
            http.getRequest(`cjMap/getFtModuleList`, data).then((res) => {
                if (res.status == 0) {
                    _that.data.ftContentArr[index].delflg =
                        res.list[index].delflg;
                    _that.setData({
                        ftContentArr: _that.data.ftContentArr,
                    });
                }
            });
        }
        if (_that.data.currentTabIndex == 1) {
            http.getRequest(`cjMap/getNFCModuleList`, data).then((res) => {
                if (res.status == 0) {
                    _that.data.nfcContentArr[index].delflg =
                        res.list[index].delflg;
                    _that.setData({
                        nfcContentArr: _that.data.nfcContentArr,
                    });
                }
            });
        }
        if (_that.data.currentTabIndex == 2) {
            http.getRequest(`cjMap/getCityOperatorList`, data).then((res) => {
                if (res.status == 0) {
                    _that.data.yysContentArr[index].delflg =
                        res.list[index].delflg;
                    _that.setData({
                        yysContentArr: _that.data.yysContentArr,
                    });
                }
            });
        }
        if (_that.data.currentTabIndex == 3) {
            http.getRequest(`cjMap/getTFATList`, data).then((res) => {
                if (res.status == 0) {
                    _that.data.cszxContentArr[index].delflg =
                        res.list[index].delflg;
                    _that.setData({
                        cszxContentArr: _that.data.cszxContentArr,
                    });
                }
            });
        }
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getLatestVerifyMsg();
    },

    // 点击头部切换
    changeNav(e) {
        this.setData({
            currentTabIndex: e.currentTarget.dataset.index,
        });
    },
    // 滑动swiper
    swiperChange(e) {
        console.log(e);
        this.setData({
            currentTabIndex: e.detail.current,
        });
    },
    pullDown: function () {
        this.setData({
            refreshing: true,
        });
        this.refresh();
    },
    infoTap: function (e) {
        // console.log(e.currentTarget.nav);
        wx.navigateTo({
            url: './myExperienceInfo/myExperienceInfo',
            success: (result) => {},
            fail: () => {},
            complete: () => {},
        });
    },
    // 获取ft列表
    getftList() {
        let _that = this;
        if (
            _that.data.ftPageNo != 0 &&
            _that.data.ftContentLength == _that.data.ftContentArr.length
        )
            return;
        _that.setData({
            ftLoading: true,
        });
        let data = {
            authId: app.globalData.authId,
            pageNo: _that.data.ftPageNo + 1,
            pageSize: 20,
            createuid: _that.data.uid,
            delflg: 'mine',
        };
        http.getRequest(`cjMap/getFtModuleList`, data).then((res) => {
            if (res.status == 0) {
                console.log(res.list);
                for (let i = 0; i < res.list.length; i++) {
                    res.list[i].createtime = app.timeago(
                        res.list[i].createtime
                    );
                    if (res.list[i].type == '11') {
                        res.list[
                            i
                        ].url = `../../../../pages/homePageInfo/ftInfo/ftInfo?id=${res.list[i].id}&otherPage=${_that.data.otherPage}`;
                    } else {
                        res.list[
                            i
                        ].url = `../../../../pages/homePageInfo/ftRouteInfo/ftRouteInfo?id=${res.list[i].id}&otherPage=${_that.data.otherPage}`;
                    }
                    _that.data.ftContentArr.push(res.list[i]);
                }
                _that.setData({
                    ftLoading: false,
                    ftPageNo: _that.data.ftPageNo + 1,
                    ftContentArr: _that.data.ftContentArr,
                    ftContentLength: res.pager.totalRows,
                });
            }
        });
    },
    // 获取nfc列表
    getnfcList() {
        let _that = this;
        if (
            _that.data.nfcPageNo != 0 &&
            _that.data.nfcContentLength == _that.data.nfcContentArr.length
        )
            return;
        _that.setData({
            nfcLoading: true,
        });
        let data = {
            authId: app.globalData.authId,
            pageNo: _that.data.nfcPageNo + 1,
            pageSize: 20,
            createuid: _that.data.uid,
            delflg: 'mine',
        };
        http.getRequest(`cjMap/getNFCModuleList`, data).then((res) => {
            if (res.status == 0) {
                for (let i = 0; i < res.list.length; i++) {
                    res.list[i].createtime = app.timeago(
                        res.list[i].createtime
                    );
                    if (res.list[i].type == '21') {
                        res.list[
                            i
                        ].url = `../../../../pages/homePageInfo/nfcInfo/nfcInfo?id=${res.list[i].id}&otherPage=${_that.data.otherPage}`;
                    } else {
                        res.list[
                            i
                        ].url = `../../../../pages/homePageInfo/nfcRouteInfo/nfcRouteInfo?id=${res.list[i].id}&otherPage=${_that.data.otherPage}`;
                    }
                    _that.data.nfcContentArr.push(res.list[i]);
                }
                _that.setData({
                    nfcLoading: false,
                    nfcPageNo: _that.data.nfcPageNo + 1,
                    nfcContentArr: _that.data.nfcContentArr,
                    nfcContentLength: res.pager.totalRows,
                });
            }
        });
    },
    // 获取运营商列表
    getyysList() {
        let _that = this;
        if (
            _that.data.yysPageNo != 0 &&
            _that.data.yysContentLength == _that.data.yysContentArr.length
        )
            return;
        _that.setData({
            yysLoading: true,
        });
        let data = {
            authId: app.globalData.authId,
            pageNo: _that.data.yysPageNo + 1,
            pageSize: 20,
            createuid: _that.data.uid,
            delflg: 'mine',
        };
        http.getRequest(`cjMap/getCityOperatorList`, data).then((res) => {
            if (res.status == 0) {
                console.log(res.data);
                for (let i = 0; i < res.data.length; i++) {
                    res.data[i].createtime = app.timeago(
                        res.data[i].createtime
                    );
                    _that.data.yysContentArr.push(res.data[i]);
                }
                _that.setData({
                    yysLoading: false,
                    yysPageNo: _that.data.yysPageNo + 1,
                    yysContentArr: _that.data.yysContentArr,
                    yysContentLength: res.pager.totalRows,
                });
            }
        });
    },
    // 获取车食住行列表
    getcszxList() {
        let _that = this;
        if (
            _that.data.cszxPageNo != 0 &&
            _that.data.cszxContentLength == _that.data.cszxContentArr.length
        )
            return;
        _that.setData({
            cszxLoading: true,
        });
        let data = {
            authId: app.globalData.authId,
            pageNo: _that.data.cszxPageNo + 1,
            pageSize: 20,
            createuid: _that.data.uid,
            delflg: 'mine',
        };
        http.getRequest(`cjMap/getTFATList`, data).then((res) => {
            if (res.status == 0) {
                console.log(res.data);
                for (let i = 0; i < res.data.length; i++) {
                    res.data[i].createtime = app.timeago(
                        res.data[i].createtime
                    );
                    if (res.data[i].type == '01') {
                        res.data[i].typeName = '录入租车信息';
                        res.data[
                            i
                        ].url = `../../cszxDetail/cszxDetail?id=${res.data[i].id}&type=01`;
                    } else if (res.data[i].type == '02') {
                        res.data[i].typeName = '录入美食信息';
                        res.data[
                            i
                        ].url = `../../cszxDetail/cszxDetail?id=${res.data[i].id}&type=02`;
                    } else if (res.data[i].type == '03') {
                        res.data[i].typeName = '录入住宿信息';
                        res.data[
                            i
                        ].url = `../../cszxDetail/cszxDetail?id=${res.data[i].id}&type=03`;
                    } else {
                        res.data[i].typeName = '录入出行信息';
                        res.data[
                            i
                        ].url = `../../cszxDetail/cszxDetail?id=${res.data[i].id}&type=04`;
                    }
                    _that.data.cszxContentArr.push(res.data[i]);
                }
                _that.setData({
                    cszxLoading: false,
                    cszxPageNo: _that.data.cszxPageNo + 1,
                    cszxContentArr: _that.data.cszxContentArr,
                    cszxContentLength: res.pager.totalRows,
                });
            }
        });
    },

    // 获取最新审核消息
    getLatestVerifyMsg() {
        let data = {
            authId: app.globalData.authId,
            origintype: '03',
        };
        http.getRequest('cjMap/getLatestVerifyMsg', data).then((res) => {
            if (res.status == 0) {
                let lastest = res.data;
                if (lastest.pctype) {
                    let typeName; //类型名称
                    //type:  01录入了FT测试点 02录入了NFC测试测试点 03录入了FT测试路线 04录入了NFC测试路线 06发布了xx城市公告 08发起了互动问答11发布了租车推荐 12发起了住宿推荐 13发布了出行建议 14发起了美食推荐 15发起了营业厅信息 16录入基站参数 17新建运营商  18新建套餐建议
                    if (lastest.pctype === '01') {
                        typeName = 'FT测试点';
                    }
                    if (lastest.pctype === '02') {
                        typeName = 'NFC测试点';
                    }
                    if (lastest.pctype === '03') {
                        typeName = 'FT测试路线';
                    }
                    if (lastest.pctype === '04') {
                        typeName = 'NFC测试路线';
                    }
                    if (lastest.pctype === '06') {
                        typeName = '城市公告';
                    }
                    if (lastest.pctype === '08') {
                        typeName = '互动问答';
                    }
                    if (lastest.pctype === '11') {
                        typeName = '租车推荐';
                    }
                    if (lastest.pctype === '12') {
                        typeName = '住宿推荐';
                    }
                    if (lastest.pctype === '13') {
                        typeName = '出行建议';
                    }
                    if (lastest.pctype === '14') {
                        typeName = '美食推荐';
                    }
                    if (lastest.pctype === '15') {
                        typeName = '营业厅';
                    }
                    if (lastest.pctype === '16') {
                        typeName = '基站参数';
                    }
                    if (lastest.pctype === '17') {
                        typeName = '运营商';
                    }
                    if (lastest.pctype === '18') {
                        typeName = '套餐建议';
                    }
                    // 处理审核消息标题
                    const action =
                        app.globalData.uid === lastest.originuid
                            ? '发布'
                            : '编辑';
                    if (lastest.type === '08') {
                        lastest.review_title = `您${action}的${typeName}被审核通过`;
                    }
                    if (lastest.type === '09') {
                        lastest.review_title = `您${action}的${typeName}因不符合要求被删除`;
                    }
                    if (lastest.type === '10') {
                        lastest.review_title = `恭喜，您${action}的${typeName}被设置为优秀`;
                    }
                } else {
                    lastest.review_title = `暂无消息`;
                }
                this.setData({
                    lastest,
                    unreadCount: res.count,
                });
            }
        });
    },
});
